package net.kornr.abstractcanvassamples.client;

import com.google.gwt.widgetideas.graphics.client.Color;

import net.kornr.abstractcanvas.client.CanvasPainter;
import net.kornr.abstractcanvas.client.ICanvasExt;

public class ColorTest implements CanvasPainter 
{

	public void drawCanvas(ICanvasExt canvas) 
	{
		double width = canvas.getCoordWidth();
		double height = canvas.getCoordHeight();

		canvas.setFillStyle(Color.WHITE);
		canvas.setGlobalAlpha(1.0);
		canvas.fillRect(0, 0, width, height);
		canvas.setLineWidth(1.0);
		
		Color[] colors = new Color[] { 
				new Color("#FF0000"), new Color("#00FF00"), new Color("#0000FF"),
				new Color("#FF7777"), new Color("#77FF77"), new Color("#7777FF"),
				new Color("#00FFFF"), new Color("#FF00FF"), new Color("#FFFF00"),
				Color.WHITE};

		for (int i=0; i<3; i++)
		{
			for (int j=0; j<3; j++)
			{
				canvas.setStrokeStyle(colors[i*3+j]);
				canvas.setFillStyle(colors[i*3+j+1]);
				canvas.setGlobalAlpha(0.3);
				canvas.beginPath();
				canvas.rect((width/3.0d)*i + offset(i), (height/3.0d)*j+offset(j), width/3, height/3);
				canvas.closePath();
				canvas.fill();
				canvas.setGlobalAlpha(0.8);
				canvas.setStrokeStyle(Color.BLACK);
				canvas.setGlobalAlpha(0.1);
				canvas.stroke();
			}
		}
	}
	
	public int offset(int i)
	{
		switch (i)
		{
		case 0: 
			return 40;
		case 1:
			return 0;
		case 2:
			return -40;
		}
		return 0;
	}

}
